
// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

import UIKit

@objc public enum ChangeType: Int {
    case TeamName = 0
    case NickName
    case TeamAlias
}

@objc
public enum TeamSettingType: Int {
    case Discuss = 0
    case Senior = 1
}

@objcMembers
open class NEBaseTeamSettingCell: UITableViewCell {
    /// 群设置数据模型
    var model: SettingCellModel?
    
    lazy var backView: UIView = {
      let backView = UIView()
      backView.backgroundColor = .white
      backView.clipsToBounds = true
      backView.translatesAutoresizingMaskIntoConstraints = false
      return backView
    }()
    
    public lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.textColor = .normalTeamTitleColor
        label.font = NEConstant.defaultTextFont(16.0)
        label.accessibilityIdentifier = "id.titleLabel"
        return label
    }()
    
    public lazy var arrowView: UIImageView = {
        let imageView = UIImageView(image: coreLoader.loadImage("right_arrow_icon"))
        imageView.translatesAutoresizingMaskIntoConstraints = false
        return imageView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .normalBackColor
                
        contentView.addSubview(backView)
        NSLayoutConstraint.activate([
            backView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: kScreenInterval),
            backView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -kScreenInterval),
            backView.topAnchor.constraint(equalTo: contentView.topAnchor),
            backView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
        ])
    }
    
    public required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    open func configure(_ anyModel: Any) {
        if let m = anyModel as? SettingCellModel {
            model = m
            titleLabel.text = m.cellName
        }
    }
    
    open override func layoutSubviews() {
        super.layoutSubviews()
        
        if let m = model {
            if m.cornerType == .topLeft.union(.topRight) {
                backView.addCorner(conrners: .topLeft.union(.topRight), radius: 6.0)
            } else if m.cornerType == .bottomLeft.union(.bottomRight) {
                backView.addCorner(conrners: .bottomLeft.union(.bottomRight), radius: 6.0)
            } else if m.cornerType == .topLeft.union(.topRight).union(.bottomLeft).union(.bottomRight) {
                backView.addCorner(conrners: .topLeft.union(.topRight).union(.bottomLeft).union(.bottomRight), radius: 6.0)
            } else {
                backView.addCorner(conrners: .allCorners, radius: 0)
            }
        }
    }
}
